package agent

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/rpc-client/agentClient/rpc"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddUserRebatesLeveLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 会员返佣等级--新增
func NewAddUserRebatesLeveLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddUserRebatesLeveLogic {
	return &AddUserRebatesLeveLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AddUserRebatesLeveLogic) AddUserRebatesLeve(req *types.UserRebatesLevelAddReq) (resp *types.IsSuccessInfo, err error) {
	rpcReq := &rpc.AddUserRebatesLevelReq{
		UserID: req.UserId,
		Level:  req.Level,
		// FeeRate:       float64(req.FeeRate),
		AvailableDays: req.AvailableDays,
	}
	if req.FeeRate >= 0 {
		rpcReq.FeeRate = float64(req.FeeRate)
	}
	report, err := l.svcCtx.AgentRPC.AddUserRebatesLevel(context.Background(), rpcReq)
	if err != nil {
		logx.Error(l.ctx, err)
		return nil, err
	}

	resp = &types.IsSuccessInfo{
		IsSuccess: report.IsSuccess,
	}

	return
}
